﻿#ifndef WEBIMAGEOBJECT_H
#define WEBIMAGEOBJECT_H

#include "QtCore/qobject.h"
#include "QtGui/qabstracttextdocumentlayout.h"

class  WebImageObject : public QObject,
                        public QTextObjectInterface
{
    Q_OBJECT
    Q_INTERFACES(QTextObjectInterface)
public:
    explicit WebImageObject(QObject *parent = Q_NULLPTR);

    virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE;
    virtual void drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE;
    QImage image(QTextDocument *doc, const QTextImageFormat &imageFormat);

    static const QString brokenImage;
    static const int objectType = QTextFormat::UserObject + 1;
signals:
    void requestDownload(QString url);
private:
    QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0);
    QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format);
};


#endif // WEBIMAGEOBJECT_H
